package com.web.web;


import com.web.entity.NoteInfo;
import com.web.entity.NoteType;
import com.web.param.*;
import com.web.service.INoteInfoService;
import com.web.util.BaseController;
import com.web.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 笔记表 前端控制器
 * </p>
 *
 * @author hgjxyz
 * @since 2020-11-18
 */
@Api(tags = "笔记表")
@RestController
@RequestMapping("/web/noteInfo")
public class NoteInfoController extends BaseController {

    @Autowired private INoteInfoService noteInfoService;

    @ApiOperation("添加笔记")
    @PostMapping("add")
    public JsonResult<Void> add(@RequestBody InsertNoteInfoDto dto) {
        this.noteInfoService.insert(dto);
        return new JsonResult<>(null);
    }

    @ApiOperation("删除笔记")
    @PostMapping("delete")
    public JsonResult<Void> delete(@RequestBody DelNoteInfo dto) {
        this.noteInfoService.delete(dto);
        return new JsonResult<>(null);
    }

    @ApiOperation("修改笔记")
    @PostMapping("put")
    public JsonResult<Void> update(@RequestBody UpdateInfoDto dto) {
        this.noteInfoService.update(dto);
        return new JsonResult<>(null);
    }

    @ApiOperation("查询自己的所有笔记")
    @GetMapping(value = "get/{token}/{typeId}")
    public JsonResult<List<NoteInfo>> getList(
            @ApiParam(name = "token", value = "token", required = true)@PathVariable("token") String token,
            @ApiParam(name = "typeId", value = "类型id", required = true)@PathVariable("typeId") String typeId) {
        return new JsonResult<>(this.noteInfoService.getByList(token, typeId));
    }

}

